<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class StockActivity extends Model
{   
    protected $table = 'stock_activities';
    //
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name',
        'user_id',
        'profile',
        'money',
        'start_time',
        'end_time',
    ];
    
    public $activityStatus = ['等待中','进行中','已结束'];

    public function status(){
        $status = ['等待中','进行中','已结束'];
        return $status[$this->status];
    }

    public function statuslabel(){
        $status = ['label-primary ','label-success','label-danger'];
        return $status[$this->status];
    }

    public function orders()
    {
        return $this->hasMany('App\Models\StockOrder','stock_activity_id','id');
    }

    public static function find_all_activity()
    {
        $activity=self::get();
        return $activity;
    }

    public static function find_activity($id)
    {
        $activity=self::find($id);
        $activity->one=$activity->user()->find($activity->user_id);
        return $activity;
    }

    public function user(){
        return $this->belongsTo('App\User');
    }

}
